<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here

// as we are now within the tab box, we have to state (call) the needed information saved in the variables of the parent function
GLOBAL $AppUI, $canRead, $canEdit;

if (!$canRead) {			// lock out users that do not have at least readPermission on this module
	$AppUI->redirect( "m=public&a=access_denied" );
}
//prepare an html table with a head section
?>
<?php
// retrieving some dynamic content using an easy database query

$q = new DBQuery();
$q->addQuery("items.*, t.name as type_name");
$q->addTable('items');
$q->addJoin("md_type",  "t", "type_id = item_type1");
//$sql = "SELECT i.*, t.name as type_name FROM items i left join md_type t on type_id = item_type1 ";	// prepare the sqlQuery command to get all quotes from the einstein table
if (isset($_POST['searchterm']) && $_POST['searchterm'] != '') {
	//$sql .= "where item_name REGEXP '" . $_POST['searchterm'] . "'";
	$q->addWhere("item_name REGEXP '" . $_POST['searchterm'] . "'");
}
if (isset($_POST['screen'])) {
	$q->addJoin('item_screens', 'scr', 'scr.item_type = t.type_id');
	$q->addWhere("item_screen='" . $_POST['screen'] . "'");
}
// pass the query to the database, please consider always using the (still poor) database abstraction layer
//$quotes = db_loadList( $sql );		// retrieve a list (in form of an indexed array) of einstein quotes via an abstract db method
$quotes = $q->loadList();
if ($quotes && is_array($quotes)) {
	echo json_encode($quotes);
}
else {
	echo '';
}
?>
